package com.zz.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 使用Stream流
 * 找出姓张并且是三个字的名字
 */
public class Test {
    public static void main(String args[]){
        List<String> names = new ArrayList <>();
        Collections.addAll(names, "张无忌", "赵四", "张三", "李四", "张缘结");
        System.out.println(names);

        //使用原始方法
        List<String> list = new ArrayList <>();
        for (String name:names) {
            if(name.startsWith("张") && name.length() == 3){
               list.add(name);
            }
        }
        System.out.println(list);

        //使用Stream流
        List<String> list1 = names.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).collect(Collectors.toList());
        System.out.println(list1);
    }
}
